package com.example.spinning.service;

import com.example.spinning.bean.endProductStock;
import com.example.spinning.mapper.EndProductStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class EndProductStockService {

    @Autowired
    private EndProductStockMapper endProductStockMapper;

    //得到成品库存信息，勿删
    //带有分页功能的展现数据
    public List<endProductStock> getAllEndProductStock(Integer page, Integer count) {
        int start = (page - 1) * count;
        return endProductStockMapper.getEndProductStock(start,count);
    }
    //找到行数
    public int getEndProductCount() {
        return endProductStockMapper.getCountEndProductStock();
    }

   //由条件找到行数
    public int getEndProductCountByCondition(String name,String batch_no, String norms, String date) {
        return endProductStockMapper.getCountEndProductStockByCondition(name,batch_no,norms,date);
    }


    //根据id查询库存产品信息
    public endProductStock getEndProductStockById(long id){
        endProductStock productStock = endProductStockMapper.getEndProduceStockById(id);
        return productStock;
    }

    //根据条件模糊查询
    public List<endProductStock> getEndProduceStockByCondition(
            Integer page, Integer count,String name,String batch_no, String norms, String date){
        int start = (page - 1) * count;
        return endProductStockMapper.getEndProductStockByCondition(start,count,name,batch_no,norms,date);
    }

    //添加成品库存记录
    //测试，仿category
    public int addEndProductStock(endProductStock productStock){
        //productStock.setDate(new Timestamp(System.currentTimeMillis()));
        return endProductStockMapper.addEndProductStock(productStock);
    }

    //修改库存产品
    public int updateEndProductStockById(endProductStock productStock){
        return endProductStockMapper.updateEndProduceStockById(productStock);
    }

    //删除库存产品
    public boolean deleteEndProductStockByIds(String ids){
        String[] split = ids.split(",");
        int result = endProductStockMapper.delEndProductStockById(split);
        return result == split.length;
    }

}
